<?php
using("Utils_HashMap");
using("Utils_ReflectionFacade");

define("JUNCTION_GET_METHOD", "get");
define("JUNCTION_SET_METHOD", "set");

class Junction_Mapping {
	
	private $_table;
	
	/**
	 * HashMap
	 *
	 * @var Utils_HashMap
	 */
	private $_properties;
	
	public function insert(array $row) {
		$query = $this->build($row, new Query_InsertBuilder($this->_table));
		if ($this->_dbh->executeSave($query)) {
			return $this->_dbh->lastInsertId();
		}
		return -1;
	}
	
	private function build(Traversable $row, Query_BuildStrategy $strategy) {
		foreach ($row as $field => $value) {
			if ($this->_properties->containsKey($field)) {
				$strategy->bindProperty($this->_properties->get($field), $value); 
			}
		}
		return $strategy;
	}
}
?>